package com.ruoyi.business.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CzLicense;
import com.ruoyi.business.service.ICzLicenseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无人机驾照Controller
 * 
 * @author ruoyi
 * @date 2022-01-09
 */
@Api(tags = "无人机驾照")
@RestController
@RequestMapping("/business/license")
public class CzLicenseController extends BaseController
{
    @Autowired
    private ICzLicenseService czLicenseService;

    /**
     * 查询无人机驾照列表
     */
    @ApiOperation(value = "查询无人机驾照列表")
    @PreAuthorize("@ss.hasPermi('business:license:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzLicense czLicense)
    {
        startPage();
        List<CzLicense> list = czLicenseService.selectCzLicenseList(czLicense);
        return getDataTable(list);
    }

    /**
     * 导出无人机驾照列表
     */
    @ApiOperation(value = "导出无人机驾照列表")
    @PreAuthorize("@ss.hasPermi('business:license:export')")
    @Log(title = "无人机驾照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzLicense czLicense)
    {
        List<CzLicense> list = czLicenseService.selectCzLicenseList(czLicense);
        ExcelUtil<CzLicense> util = new ExcelUtil<CzLicense>(CzLicense.class);
        util.exportExcel(response, list, "无人机驾照数据");
    }

    /**
     * 获取无人机驾照详细信息
     */
    @ApiOperation(value = "获取无人机驾照详细信息")
    @PreAuthorize("@ss.hasPermi('business:license:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(czLicenseService.selectCzLicenseById(id));
    }

    /**
     * 新增无人机驾照
     */
    @ApiOperation(value = "新增无人机驾照")
    @PreAuthorize("@ss.hasPermi('business:license:add')")
    @Log(title = "无人机驾照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzLicense czLicense)
    {
        return toAjax(czLicenseService.insertCzLicense(czLicense));
    }

    /**
     * 修改无人机驾照
     */
    @ApiOperation(value = "修改无人机驾照")
    @PreAuthorize("@ss.hasPermi('business:license:edit')")
    @Log(title = "无人机驾照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzLicense czLicense)
    {
        return toAjax(czLicenseService.updateCzLicense(czLicense));
    }

    /**
     * 删除无人机驾照
     */
    @ApiOperation(value = "删除无人机驾照")
    @PreAuthorize("@ss.hasPermi('business:license:remove')")
    @Log(title = "无人机驾照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(czLicenseService.deleteCzLicenseByIds(ids));
    }
}
